﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RuleOfReady.Core.DomainModels.Tiles;

namespace RuleOfReady.Core.DomainModels.Sets
{
    /// <summary>
    /// Object representing a Mahjong Pair (Japanese: 'atama', 'Jantō', toitsu')
    /// A pair is two identical tiles (eg. 2c 2c)
    /// </summary>
    public class MahjongPair : MahjongPossibleSet
    {

        #region MahjongPossibleSet Properties

        /// <summary>
        /// The tiles that make up the pair
        /// </summary>
        public override IEnumerable<MahjongTile> Tiles { get; protected set; }

        /// <summary>
        /// Tiles waited on to complete the set
        /// </summary>
        public override IEnumerable<MahjongTile> WaitingTiles { get; protected set; }

        /// <summary>
        /// Flag: a pair is not a completed set
        /// </summary>
        public override bool CompletedSet { get; protected set; }

        #endregion

        /// <summary>
        /// Create a new Pair of Mahjong tiles, of the given tile type
        /// </summary>
        /// <param name="tile">type of tiles the pair is made of</param>
        public MahjongPair(MahjongTile tile)
        {
            this.Tiles = Enumerable.Repeat(tile, 2);
            this.WaitingTiles = new[] { tile };
            this.CompletedSet = true;
        }

        /// <summary>
        /// (MahjongPossibleSet) Creates a new triple set from this pair and a given identical tile
        /// </summary>
        /// <param name="addTile">tile to add tot he set</param>
        /// <returns>the new triple, or null if the given tile isn't identical</returns>
        public override MahjongPossibleSet Add(MahjongTile addTile)
        {
            if (this.WaitingTiles.Contains(addTile))
                return new MahjongTriple(this.Tiles.First());
            else return null;
        }
    }
}

